package zoltan.balog.run;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import zoltan.balog.generator.impl.ReaderGenerator;
import zoltan.balog.solver.ISolver;
import zoltan.balog.solver.impl.GreedySolver;
import zoltan.balog.solver.impl.SortedGreedySolver;

public class Main {

	private final static String GREEDY = "GreedySolver";
	private final static String SORTED_GREEDY = "SortedGreedySolver";

	public static void main(final String[] args) {
		
		
		final ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/beans.xml");
		final BeanFactory factory = context;
		final Runner runner = (Runner) factory.getBean("runner");
		ISolver solver = null;
		
		if (args.length != 2) {
			Logger.getAnonymousLogger().log(Level.WARNING, "Wrong inputs!");
			System.exit(1);
		}
		
		if (args[0].equalsIgnoreCase(GREEDY)) {
			solver = new GreedySolver();
		} else if (args[0].equalsIgnoreCase(SORTED_GREEDY)) {
			solver = new SortedGreedySolver();
		} else {
			Logger.getAnonymousLogger().log(Level.WARNING, "Wrong input name for Solver!");
			System.exit(1);
		}
		
		if (null != args[1] && !args[1].isEmpty()) {
				ReaderGenerator generator = new ReaderGenerator();
				generator.setFile(args[1]);
				runner.setGenerator(generator);
				runner.setSolver(solver);
		}
		
		runner.run();
	}
}